$(function () {
    let markId = getUrlString('markid');
    let toUserName = getUrlString('toUserName');
    let userId = toUserName.substring(7);
    $('.name').click(function () {
        window.location.href = 'dancool://member='+userId;
    });


    //获取用户信息
    function getUserInfo() {
        var data = {
            'markid':markId,
            'userid':userId
        };
        getData('post','/niu/api/weibo_getuserinfo.php',data,function (data) {
            console.log(data);
            $('#faceurl').attr('src',data.faceurl);
            if (data.markusername === '' || data.markusername === null){
                $('#nickName').html(data.nick);
            } else {
                $('#nickName').html(data.nick+'('+data.markusername+')');
            }
            //判断是否在黑名单之列  0不在  1在
            if(data.inblack === '0'){
                $('#addBlack').html('加入黑名单').click(function () {
                    var data = {
                        'set':'add',
                        'blockuserid':userId,
                        'markid':markId
                    };
                    getData('post','/niu/api/weibo_doblackuser.php',data,function (data) {
                        console.log(data);
                        laymsg(data.msg);
                        setTimeout(function () {
                            window.location.reload()
                        },500)
                    })
                });
            }else {
                $('#addBlack').html('移除黑名单').click(function () {
                    var data = {
                        'set':'del',
                        'blockuserid':userId,
                        'markid':markId
                    };
                    getData('post','/niu/api/weibo_doblackuser.php',data,function (data) {
                        console.log(data);
                        laymsg(data.msg);
                        setTimeout(function () {
                            window.location.reload()
                        },500)
                    })
                });
            }
        })
    }

    getUserInfo();

    //更新好友备注
    function upDataUserName(markid,friendid,markname) {
        if (markname === ''){
            laymsg('备注名不能为空');
            return
        }

        let data = {
            'markid':markid,
            'friendid':friendid,
            'markname':markname,
            'markinfo':'备注',
        };
        console.log(data)

        getData('post','/niu/apiv3/weibo_friend.php?method=updateFriendMark',data,function (data) {
            console.log(data);
            $('#indexAlert').fadeOut();
            if (data.resultcode === '0') {
                laymsg('更新备注成功');
            }else {
                laymsg(data.msg);
            }
        })
    }

    //更新好友备注
    function jbUserName(markid,friendid,markname) {
        if (markname === ''){
            laymsg('举报内容不能为空');
            return
        }
        let data = {
            'markid':markid,
            'title':'用户id'+friendid,
            'intro':markname,
        };

        getData('post','/niu/apiv4/niu_user_jubao.php',data,function (data) {
            console.log(data);
            $('#indexAlert2').fadeOut();
            if (data.resultcode === '0') {
                laymsg('举报成功');
            }else {
                laymsg(data.msg);
            }
        })
    }

    $('#reMakeBtn').click(function () {
        $('#indexAlert').fadeIn();
    });

    $('#qubao').click(function () {
        $('#indexAlert2').fadeIn();
    });

    $('#QDBtn').click(function () {
        let markname = $('#reMake').val();
        upDataUserName(markId,userId,markname)
    });

    $('#QXBtn').click(function () {
        $('#indexAlert').fadeOut();
    });

    $('#QBQDBtn').click(function () {
        let markname = $('#jubaoVal').val();
        jbUserName(markId,userId,markname)
    });

    $('#QBQXBtn').click(function () {
        $('#indexAlert2').fadeOut();
    });



    //判断两人是否是好友
    function isFrd() {
        getData('get','/niu/apiv3/weibo_friend.php?method=isMyFriend',{'markid':markId,'friendid':userId},function (data) {
            console.log(data);
            if(data.ismyfriend === '0'){
                $('.deleteFrd').html('加好友').click(function () {
                    window.location.href = 'dancool://fullweb='+urlView+'messagesV2/verifyFrd.html?id='+userId;
                });
            }else{
                $('.deleteFrd').html('删除好友').click(function () {
                    getData('post','/niu/apiv3/weibo_friend.php?method=removeFriend',{'markid':markId,'friendid':userId},function (data) {
                        console.log(data);
                        if (data.resultcode === '0'){
                            laymsg('删除成功');
                            setTimeout(function () {
                                window.location.reload()
                            },1000)
                        }
                    });
                });
            }
        })
    }
    isFrd();
});
